package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet{
	private static final long serialVersionUID=1L;
	protected void doGet(HttpServletRequest req,HttpServletResponse resp)throws IOException,ServletException{
		doPost(req,resp);
	}
	
	protected void doPost(HttpServletRequest req,HttpServletResponse resp)throws IOException,ServletException{
		req.setCharacterEncoding("utf-8");
		String userName=req.getParameter("userName");
		String userPwd=req.getParameter("userPwd");
		if("admin".equals(userName) && "123456".equals(userPwd)) {
			HttpSession session=req.getSession();
			session.setAttribute("userName",userName);
			resp.sendRedirect("index.jsp");
			return;
		}
		else {
			req.setAttribute("message", "用户名或密码错误");
			req.getRequestDispatcher("login.jsp").forward(req, resp);
			return;
		}
	}

}
